/**
 * Created by leo on 2/2.
 */
angular.module('panels')
    .directive('panelBomMyServicesStatus', function (loadConf, $http, tabService) {
        return {
            scope: {},
            link: function (scope) {
                loadConf('panel-bom-my-services-status.yml').then(function (setting) {
                    scope.more = setting.more;
                    scope.types = setting.types;
                    scope.changeType = function (index) {
                        scope.types.currentOn = index;
                        $http.jsonp(setting.listQueryUrl, {
                            params: {
                                resType: scope.types[index].id.split(','),
                                rowCount: 10
                            }
                        }).success(function (rows) {
                            scope.rows = rows;
                        });
                    };
                    scope.changeType(0);

                    // 打开综合视图
                    scope.openIntegrateView = function (row) {
                        tabService.addTab({
                            name: row.RES_NAME,
                            url: setting.integrateViewUrl.replace('{UNIT_ID}', row.UNIT_ID)
                        });
                    };
                    // 打开告警视图
                    scope.openAalrmView = function (row) {
                        tabService.addTab({
                            name: row.IP_ADDR,
                            url: setting.alarmViewUrl.replace('{UNIT_ID}', row.UNIT_ID)
                        });
                    };
                });
            },
            templateUrl: 'app/panel/bom/my-services-status.html'
        };
    });